package uk.ac.aber.Blockmation.Tests;

import java.awt.BorderLayout;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JScrollBar;

import uk.ac.aber.Blockmation.Display;
import uk.ac.aber.Blockmation.MovieModel;

public class DisplayTest {
	
    private static MovieModel model = new MovieModel();
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {

        JFrame f = new JFrame("Pad Example");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        final Display display = new Display();		
        f.getContentPane().add( display, BorderLayout.NORTH );

        //JScrollPanel view = JScrollPane


        BufferedImage bim;
        bim = ImageIO.read( new File("src/uk/ac/aber/Blockmation/Tests/1.bmp"));
        model.appendFrame(bim );
        bim = ImageIO.read( new File("src/uk/ac/aber/Blockmation/Tests/2.bmp"));
        model.appendFrame(bim );
        bim = ImageIO.read( new File("src/uk/ac/aber/Blockmation/Tests/3.bmp"));
        model.appendFrame(bim );
        bim = ImageIO.read( new File("src/uk/ac/aber/Blockmation/Tests/4.bmp"));
        model.appendFrame(bim );

        AdjustmentListener adjustmentListener = new AdjustmentListener() 
        {
            public void adjustmentValueChanged(AdjustmentEvent adjustmentEvent) {
                System.out.println("Adjusted: " + adjustmentEvent.getValue());
                display.setImage(model.get( adjustmentEvent.getValue() ));
            }
        };

        JScrollBar bar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 0, 0, model.size()-1);
        bar.addAdjustmentListener(adjustmentListener);
        bar.setBlockIncrement(1);

        f.getContentPane().add(bar, BorderLayout.SOUTH);



        BufferedImage image = ImageIO.read( 
                        new File ("src/uk/ac/aber/Blockmation/Tests/1.bmp"));    
        // tests setting image to this new image
        display.setImage(image);

        //sets different block size
        //display.setBlockSize(new Dimension(40,40));

        //f.setPreferredSize(new Dimension(400,400));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);



    }

}
